package com.chixing.service.impl;


import com.chixing.mapper.CustomerMapper;
import com.chixing.mapper.HotelMapper;
import com.chixing.mapper.MyorderMapper;
import com.chixing.pojo.*;
import com.chixing.service.MyOrderService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MyOrderServiceImpl implements MyOrderService {
    @Autowired
    private MyorderMapper myorderMapper;
    @Autowired
    private HotelMapper hotelMapper;

    @Override
    public ServerResponse getByCusAndHotelId(Integer cusId) {
        MyorderExample myorderExample = new MyorderExample();
        myorderExample.createCriteria().andCusIdEqualTo(cusId);
        List<Myorder> myorderList = myorderMapper.selectByExample(myorderExample);
        List<MyorderVoHotel> myorderVoHotelList = new ArrayList<>();



        for (Myorder myorder:myorderList){
            MyorderVoHotel myorderVoHotel = new MyorderVoHotel();
            Hotel hotel = hotelMapper.selectByPrimaryKey(myorder.getHotelId());
            myorderVoHotel.setMyorder(myorder);
            myorderVoHotel.setHotel(hotel);
            myorderVoHotelList.add(myorderVoHotel);
        }

        if (myorderVoHotelList != null && myorderVoHotelList.size() > 0)
            return ServerResponse.getSuccess(myorderVoHotelList);
        return ServerResponse.getFail(null);
    }

/*    @Override
    public ServerResponse getByCusId(Integer cusId) {
        MyorderExample myorderExample = new MyorderExample();
        myorderExample.createCriteria().andCusIdEqualTo(cusId);
        List<Myorder> myorderList = myorderMapper.selectByExample(myorderExample);
        if (myorderList != null && myorderList.size() > 0)
            return ServerResponse.getSuccess(myorderList);
        return ServerResponse.getFail(null);
    }*/
}